var express = require('express');
var router = express.Router();
const { show, change, creat } = require("../controllers/pjw-pim");
router.get('/renderpim', show);
router.post('/changepim', change);
router.post('/creatpim', creat);

const { uploadFiles } = require('../utils/handleFiles');
router.post('/uploadImages', function (req, res, next) {//上传图片
    //图片上传
    const uploadImages = uploadFiles({
        //图片上传成功后的储存路径
        dir: './public/temp',
        size: 30000
    });
    uploadImages(req, res, (error) => {
        if (error) {
            console.log('图片上传失败', error);
        } else {
            console.log('图片上传成功');
            res.send({
                message: '图片上传成功',
                code: 200,
                data: 'http://localhost:3100/./temp/' + req.files[0].filename
            })
        }
    })
})
module.exports = router;